<?php
    echo $this->Form->create('false', array('type' => 'file', 'class' => 'form-horizontal', 'role' => 'form', 'method' => 'get'));

    echo $this->Html->div('panel panel-default',
            $this->Html->div('panel-body',
                    $this->Html->div('form-group',
                            $this->Form->label('SearchByLabel', 'Cari Dengan', array('class' => 'col-sm-2 control-label')) .
                            $this->Html->div('col-sm-10', 
                               $this->Form->select('SearchBy'
                                       , array(
                                           'AJU' => 'AJU'
                                           , 'TglPendaftaran' => 'Tgl. Pendaftaran'
                                           )
                                       , array(
                                           'class' => 'form-control'
                                           , 'onchange' => 'return checkSearchBy()'
                                           )))
                            ) . 
                    $this->Html->div('form-group',
                            $this->Form->label('AJULabel', 'AJU', array('class' => 'col-sm-2 control-label')) .
                            $this->Html->div('col-sm-10', 
                               $this->Form->text('AJU', array(
                                   'class' => 'form-control'
                               )))
                            , array(
                                'id' => 'AJUDialog'
                            )
                            ) .
                    $this->Html->div('form-group',
                            $this->Form->label('TglPendaftaranLabel', 'Tgl. Pendaftaran', array('class' => 'col-sm-2 control-label')) .
                            $this->Html->div('col-sm-10', 
                               $this->Form->dateTime('TglPendaftaran', 'DMY', array(
                                   'class' => 'form-control'
                               )))
                            , array(
                                'id' => 'TglPendaftaranDialog'
                            )
                            ) .
                    $this->Html->div('form-group',
                            $this->Html->div('col-sm-offset-2 col-sm-10',
                            $this->Form->end('Search', array('class' => 'btn btn-default'))
                )
            )
                    )
            );
    
?>
<script>

function checkSearchBy()
{
    var searchBy = $("#falseSearchBy").val();
    
    if(searchBy == 'AJU')
    {
        $("#AJUDialog").show();
        $("#TglPendaftaranDialog").hide();
    }
    else if(searchBy == 'TglPendaftaran')
    {
        $("#AJUDialog").hide();
        $("#TglPendaftaranDialog").show();
    }
    else
    {
        $("#AJUDialog").show();
        $("#TglPendaftaranDialog").show();
        $("#falseAJU").val('');
        $("#falseTglPendaftaranDay").val('');
    }
    
}

</script>

    <h2 class="sub-header">Data PIB</h2>
      <div class="table-responsive">
        <table class="table table-striped">
          <thead>
            <tr>
              <th>#</th>
              <th><?php echo $this->Paginator->sort('CAR', 'AJU'); ?></th>
              <th>Tgl. Pendaftaran</th>
              <th>Tgl. Generate CUSRES</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
            <?php 
                $counter = 1;
                
                foreach($allHeader as $header)
                {
            ?>
            <tr>
                <td><?php echo $counter; ?></td>
                <td><?php echo $header['Header']['CAR']; ?></td>
                <td><?php echo $header['Header']['PibTg']; ?></td>
                <td><?php echo '-'; ?></td>
                <td>
                    <?php 
                    if($header['Header']['isEdited'] == true)
                    {
                        echo $this->Html->link('Generate CUSRES', array('controller' => 'pibs', 'action' => 'cusresexportconfirm', $header['Header']['CAR'])) . ' | ';
                    }
                    echo //$this->Html->link('View Detail', '#') . ' | ' .
                        $this->Html->link('Edit Invoice Detail', array('controller' => 'pibs', 'action' => 'editlinkinvoice', $header['Header']['CAR'])); 
                    ?>
                </td>
            </tr>
            <?php
                    $counter++;
                }
            ?>
          </tbody>
        </table>
      </div>
    <div><?php //print_r($allHeader); ?></div>
    <div><?php //print_r($test); ?></div>
    <script>
        window.onload = function()
        {
            checkSearchBy();
        };
    </script>
    